package com.jsp.controller.usercontroller;

import com.jsp.entity.UserVO;
import com.jsp.mapper.impl.DepartMapperImpl;
import com.jsp.mapper.impl.UserMapperImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet(name = "UserDeleteServlet", value = "/userDelete")
//删除字段
public class UserDeleteServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response){
        try {
            //获取前端id
            String yhid = request.getParameter("YHID");
            UserMapperImpl userMapper = new UserMapperImpl();
            userMapper.delUser(yhid);
            List<UserVO> collect = UserLoginServlet.getUserVOS();
            request.setAttribute("userList", collect);
            DepartMapperImpl departMapper = new DepartMapperImpl();
            request.setAttribute("departList", departMapper.findAll());
            request.getRequestDispatcher("/list.jsp").forward(request, response);
        }catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
